using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
namespace MicroMsg.UI.UserContrl
{
	public class SimileyPad : UserControl
	{
		private const string TAG = "SimileyPad";
		private const double cDStartX = 9.0;
		private const double cDStartY = 0.0;
		private const double cDSmileyW = 480.0;
		private const double cDSmileyH = 330.0;
		private const double cDItemDis = 2.0;
		private const double cDItemW = 64.0;
		private const double cDItemH = 64.0;
		private const double cDItemColCnt = 7.0;
		private const double cDItemRowCnt = 5.0;
		public int mNPageIndex;
		private Point mPTouchIn;
		private int mNRow = -1;
		private int mNCol = -1;
		private bool mBIsMoveOut;
		internal Grid LayoutRoot;
		internal Image imgContent;
		internal Rectangle rectCover;
		private bool _contentLoaded;
		public event MMStandardUIEvent mItemClicked;
		public SimileyPad()
		{
			this.InitializeComponent();
			this.rectCover.set_Height(64.0);
			this.rectCover.set_Width(64.0);
		}
		private void imgContent_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			this.touchIn(e.get_ManipulationOrigin().get_X(), e.get_ManipulationOrigin().get_Y());
		}
		private void imgContent_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
		{
			this.touchMove(e.get_DeltaManipulation().get_Translation().get_X(), e.get_DeltaManipulation().get_Translation().get_Y());
		}
		private void imgContent_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			this.touchUp(e.get_TotalManipulation().get_Translation().get_X(), e.get_TotalManipulation().get_Translation().get_Y());
		}
		private void touchIn(double double_0, double double_1)
		{
			this.mBIsMoveOut = false;
			this.mPTouchIn = new Point(double_0, double_1);
			int nRow = (int)((double_1 - 0.0) / 66.0);
			int nCol = (int)((double_0 - 9.0) / 66.0);
			Point itemPos = this.getItemPos(nRow, nCol);
			this.rectCover.set_Margin(new Thickness(itemPos.get_X() + 1.0, itemPos.get_Y() + 1.0, 0.0, 0.0));
			this.rectCover.set_Visibility(0);
			this.mNRow = nRow;
			this.mNCol = nCol;
		}
		private void touchMove(double double_0, double double_1)
		{
			Point point_ = new Point(this.mPTouchIn.get_X() + double_0, this.mPTouchIn.get_Y() + double_1);
			if (!this.isPointInItem(point_, this.mNRow, this.mNCol))
			{
				this.mBIsMoveOut = true;
				this.rectCover.set_Visibility(1);
			}
		}
		private void touchUp(double double_0, double double_1)
		{
			if (!this.mBIsMoveOut)
			{
				int itemIndex = this.getItemIndex(this.mNRow, this.mNCol);
				if (this.mItemClicked != null)
				{
					this.mItemClicked(this, itemIndex);
				}
			}
			this.rectCover.set_Visibility(1);
			this.mPTouchIn = new Point(0.0, 0.0);
		}
		private bool isPointInItem(Point point_0, int nRow, int nCol)
		{
			Point itemPos = this.getItemPos(nRow, nCol);
			double num = point_0.get_X() - itemPos.get_X();
			double y;
			point_0.set_Y(y = itemPos.get_Y());
			double num2 = y;
			return num >= 0.0 && num <= 66.0 && (num2 >= 0.0 && num2 <= 66.0);
		}
		private Point getItemPos(int nRow, int nCol)
		{
			Point result = default(Point);
			result.set_X(9.0 + (double)nCol * 66.0);
			result.set_Y(0.0 + (double)nRow * 66.0);
			return result;
		}
		private int getItemIndex(int nRow, int nCol)
		{
			return (int)(35.0 * (double)this.mNPageIndex + (double)nRow * 7.0 + (double)nCol);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/SimileyPad.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.imgContent = (Image)base.FindName("imgContent");
			this.rectCover = (Rectangle)base.FindName("rectCover");
		}
	}
}
